﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Users_Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindList();
        }
    }

    private void bindList()
    {
        DateTime dtime = DateTime.Now;
        int year = dtime.Year - 4;
        for (int i = 0; i < 6; i++)
        {
            ListItem lt = new ListItem();
            lt.Text = (year + i).ToString();
            ddlYear.Items.Add(lt);
        }
    }

    protected void btnRegister_Click(object sender, EventArgs e)
    {
        string studName = txtName.Text.Trim();
        string studIdcard = txtIdcard.Text.Trim();
        if (User_Control.getStudInfoByIdCard(studIdcard).Rows.Count == 0)
        {
            string studId = "xyzz" + txtStudId.Text.Trim();
            //string userID = "xyzz" + studId;    //获得用户名
            //验证用户名是否存在
            if (!User_Control.UserExist(studId))
            {
                string studSex = string.Empty;
                if (rbMale.Checked)
                {
                    studSex = "男";
                }
                else
                {
                    studSex = "女";
                }
                string studClass = txtClassName.Text.Trim();
                string studDept = txtDeptName.Text.Trim();

                string studFrom = tbFrom.Text.Trim();
                string enterYear = ddlYear.SelectedItem.Text.Trim();
                string tel = txtPhone.Text.Trim();
                if (User_Control.insertNewStudentInfo(studName, studIdcard, studSex, studId, studFrom, studDept, studClass, enterYear, tel))
                {
                    //errorTips.Visible = true;
                    //errorTips.Text = "提交成功,请等待审核!";
                    //Response.Redirect(BSUtility.mainUrl + "Users/UserLogin.aspx");
                    BSUtility.JavaScript(Page, "alert('注册成功，下面将转向登录页面登录');window.location.href='" + BSUtility.mainUrl + "Users/UserLogin.aspx'");
                }
                else
                {
                    errorTips.Visible = true;
                    errorTips.Text = "注册失败，请联系管理员!";
                }
            }
            else
            {
                errorTips.Visible = true;
                errorTips.Text = "该学号已存在,请修改学号全称或加上学校简称!";
            } 
        }
        else
        {
            errorTips.Visible = true;
            errorTips.Text = "该身份证号已存在,请返回登录，如有疑异，请联系教务科!";
        }        
    }
}